/**
 * 手写hook实现加法器
 * useReducer
 */
import { useReducer } from 'react';

export const useAdder = (initialValue) => {
  const [value, dispatch] = useReducer((state, action) => {
    return state + action;
  }, initialValue);

  return [value, dispatch];
};
/** 
 * 使用
 */
const [value, dispatch] = useAdder(0);
console.log(value);
dispatch(1);
console.log(value);
dispatch(2);
console.log(value);